package fr.afcepf.ai90.venteenligne.data;

import static org.junit.Assert.*;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.junit.Before;
import org.junit.Test;

import fr.afcepf.ai90.venteenligne.entity.Personne;
import fr.afcepf.ai90.venteenligne.interfaces.IDataPersonne;

public class TestDataPersonne {
    private IDataPersonne iDataPersonne;

    private String bonMail = "toto@t.fr";
    private String mauvaisMail = "azerty@t.fr";
    private String bonMdp = "toto";
    private Personne persEchec = null;
    private Personne persOk = null;

    @Before
    public void setUp() {
        String dateN = "12-12-2012";
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        try {
            persOk = new Personne(1, "toto", "toto", dateFormat.parse(dateN),
                    "toto@t.fr", "toto");
        } catch (ParseException e) {
       
            e.printStackTrace();
        }
        // initialisation de dataPersonne
        iDataPersonne = new DataPersonneImpl();
        // Recharger la BDD
        
        System.out.println("dans le set up");
        
        try {
            String monDotBat = Thread.currentThread().getContextClassLoader()
                    .getResource("creer_base.bat").getPath();

            Process process = Runtime.getRuntime().exec(monDotBat);
        } catch (IOException e) {
     
            e.printStackTrace();
        }
    }

    @Test
    public void textConnexionOk() {
        Personne pers = iDataPersonne.verifConnection(bonMail, bonMdp);
        assertNotNull(pers);
        assertNotNull(pers.getId());
        assertNotNull(pers.getNom());
        assertNotNull(pers.getPrenom());
        assertNotNull(pers.getDateNaissance());
        assertNotNull(pers.getMdp());
        assertNotNull(pers.getMail());

        assertEquals(persOk.getId(), pers.getId());
        assertEquals(persOk.getNom(), pers.getNom());
        assertEquals(persOk.getPrenom(), pers.getPrenom());
        assertEquals(persOk.getDateNaissance(), pers.getDateNaissance());
        assertEquals(persOk.getMdp(), pers.getMdp());
        assertEquals(persOk.getMail(), pers.getMail());
    }

    @Test
    public void textConnexionPasOk() {
        Personne pers = iDataPersonne.verifConnection(mauvaisMail, bonMdp);
        assertNull(pers);
    }
}
